package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constant.ArticleConstants;
import com.heima.model.common.dtos.app.*;
import com.heima.model.common.dtos.common.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * app端相关请求接口
 */
@Api(value = "/api/v1/article", tags = {"app端相关请求接口"})
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {
    @Autowired
    private ApArticleService apArticleService;
    /**
     * 加载首页
     * @param articleHomeDto
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ArticleHomeDto", name = "articleHomeDto", value = "", required = true)
    })
    @ApiOperation(value = "加载首页", notes = "加载首页", httpMethod = "POST")
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载最多
     * @param articleHomeDto
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ArticleHomeDto", name = "articleHomeDto", value = "", required = true)
    })
    @ApiOperation(value = "加载最多", notes = "加载最多", httpMethod = "POST")
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载最新
     * @param articleHomeDto
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ArticleHomeDto", name = "articleHomeDto", value = "", required = true)
    })
    @ApiOperation(value = "加载最新", notes = "加载最新", httpMethod = "POST")
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 保存文章信息并返回文章Id
     * @param articleDto
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ArticleDto", name = "articleDto", value = "", required = true)
    })
    @ApiOperation(value = "保存文章信息并返回文章Id", notes = "保存文章信息并返回文章Id", httpMethod = "POST")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto articleDto) {
        return apArticleService.saveArticle(articleDto);
    }

    /**
     * 加载文章行为-数据回显
     * @param articleDto
     * @return
     */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto articleDto) {
        return apArticleService.loadArticleBehavior(articleDto);
    }

    /**
     * 分页查询所有已发布app端文章信息
     * @param articlePageDto
     * @return
     */
    @PostMapping("/findAll")
    public ResponseResult findAll(@RequestBody ArticlePageDto articlePageDto) {
        return apArticleService.findAll(articlePageDto);
    }
}
